﻿    $(document).ready(function () {


        // DETAIL 2 PAGE LOAD START HERE


        $('#DetailsView2_UPFRONT_DISCOUNT').hide();
        $('#DetailsView2_OFFER_PARTNER').hide();


        $('#DetailsView2_AFFILIATION_INITIAL').hide();
        $('#DetailsView2_AFFILIATION_SURNAME').hide();
        $('#DetailsView2_AFFILIATION_MEMBER_NO').hide();

        $('#DetailsView2_SMARTER_PAY_CREDIT').hide();

        $('#DetailsView2_SelTITLE_CUST_2').hide();
        $('#DetailsView2_FIRST_NAME_CUST_2').hide();
        $('#DetailsView2_LAST_NAME_CUST_2').hide();
        $('#DetailsView2_DOB_CUST_2').hide();
        $('#DetailsView2_DRIVERS_LICENCE_CUST_2').hide();
        $('#DetailsView2_HPHONE_CUST_2').hide();
        $('#DetailsView2_BPHONE_CUST_2').hide();
        $('#DetailsView2_MOBILE_CUST_2').hide();
        $('#DetailsView2_EMAIL_CUST_2').hide();
        $('#DetailsView2_SelRELATIONSHIP_CODE').hide();

        //RPO seleted
        if ($('#DetailsView2_SelPAYMENT_OPTION').val() == 'RPO') {
            $('#DetailsView2_RPO_FIRST_PAYMENT_DATE').show();
            $('#DetailsView2_RPO_ELEC_MONTH').show();
            $('#DetailsView2_RPO_ELEC_FORTN').show();
            $('#DetailsView2_RPO_GAS_MONTH').show();
            $('#DetailsView2_RPO_GAS_FORTN').show();
            $('#DetailsView2_RPO_COMB_MONTH').show();
            $('#DetailsView2_RPO_COMB_FORTN').show();
            $('#DetailsView2_RPO_FREQ_SELECTION').show();
        }
        else {
            $('#DetailsView2_RPO_FIRST_PAYMENT_DATE').hide();
            $('#DetailsView2_RPO_ELEC_MONTH').hide();
            $('#DetailsView2_RPO_ELEC_FORTN').hide();
            $('#DetailsView2_RPO_GAS_MONTH').hide();
            $('#DetailsView2_RPO_GAS_FORTN').hide();
            $('#DetailsView2_RPO_COMB_MONTH').hide();
            $('#DetailsView2_RPO_COMB_FORTN').hide();
            $('#DetailsView2_RPO_FREQ_SELECTION').hide();

        }




        if ($('#DetailsView2_SelCUSTOMER_TYPE').val() == 'RESD') {

            $('#DetailsView2_BILLNAME1').hide();
            $('#DetailsView2_BILLNAME2').hide();

            $('#DetailsView2_lblCUSTOMER_TYPE').hide();
            $('#DetailsView2_SelSOHO').show();

            $('#DetailsView2_TRADING_NAME').hide();

            if ($('#DetailsView2_ANNUAL_CONSUMPTION').val() == '') {
                document.getElementById('DetailsView2_ANNUAL_CONSUMPTION').value = "2";
            }

            if ($('#DetailsView2_SelSOHO').val() == 'Not SOHO') {
                $('#DetailsView2_COMPANY_NAME').hide();
                $('#DetailsView2_COMPANY_POSITION').hide();
                $('#DetailsView2_ABN').hide();
                //$('#DetailsView2_ANNUAL_CONSUMPTION').hide();

                //var myVal = document.getElementById('DetailsView2_COMPANY_NAMEVali');
                //ValidatorEnable(myVal, false);
                //var myVal = document.getElementById('DetailsView2_COMPANY_POSITIONVali');
                //ValidatorEnable(myVal, false);
                //var myVal = document.getElementById('DetailsView2_ABNVali');
                //ValidatorEnable(myVal, false);

                //var myVal = document.getElementById('DetailsView2_ANNUAL_CONSUMPTIONVali');
                //ValidatorEnable(myVal, false);
            }
            if ($('#DetailsView2_SelSOHO').val() != 'Not SOHO') {
                $('#DetailsView2_lblCUSTOMER_TYPE').show();
                $('#DetailsView2_COMPANY_NAME').show();
                $('#DetailsView2_COMPANY_POSITION').show();
                $('#DetailsView2_ABN').show();
                //$('#DetailsView2_ANNUAL_CONSUMPTION').show();

                //var myVal = document.getElementById('DetailsView2_COMPANY_NAMEVali');
                //ValidatorEnable(myVal, true);
                //var myVal = document.getElementById('DetailsView2_COMPANY_POSITIONVali');
                //ValidatorEnable(myVal, true);
                //var myVal = document.getElementById('DetailsView2_ABNVali');
                //ValidatorEnable(myVal, true);

                //var myVal = document.getElementById('DetailsView2_ANNUAL_CONSUMPTIONVali');
                //ValidatorEnable(myVal, true);

            }






            ///var myVal = document.getElementById('DetailsView2_EMAILVali');
            ///ValidatorEnable(myVal, false);

            if ($('#DetailsView2_SelCALL_TYPE').val() == 'D2D') {
                $('#DetailsView2_SelCUST2').show();
                $('#DetailsView2_ACCOUNT_ID').hide();
                $('#DetailsView2_SelPAYMENT_OPTION').hide();
            }
            if ($('#DetailsView2_SelCALL_TYPE').val() == 'INBOUND' || $('#DetailsView2_SelCALL_TYPE').val() == 'OUTBOUND') {
                $('#DetailsView2_SelCUST2').hide();
                $('#DetailsView2_ACCOUNT_ID').show();
                $('#DetailsView2_SelPAYMENT_OPTION').show();
            }
            ///var myVal = document.getElementById('DetailsView2_CURRENT_ELECTRICITY_RETAILERVali');
            ///ValidatorEnable(myVal, false);

        }

        if ($('#DetailsView2_SelCUSTOMER_TYPE').val() == 'SME') {

            if ($('#DetailsView2_ANNUAL_CONSUMPTION').val() == '') {
                document.getElementById('DetailsView2_ANNUAL_CONSUMPTION').value = "1";
            }

            $('#DetailsView2_BILLNAME1').show();
            $('#DetailsView2_BILLNAME2').show();

            $('#DetailsView2_lblCUSTOMER_TYPE').show();
            $('#DetailsView2_SelSOHO').hide();
            $('#DetailsView2_COMPANY_NAME').show();
            $('#DetailsView2_COMPANY_POSITION').show();
            $('#DetailsView2_ABN').show();
            //$('#DetailsView2_ANNUAL_CONSUMPTION').show();
            //var myVal = document.getElementById('DetailsView2_COMPANY_NAMEVali');
            //ValidatorEnable(myVal, true);
            //var myVal = document.getElementById('DetailsView2_COMPANY_POSITIONVali');
            //ValidatorEnable(myVal, true);
            //var myVal = document.getElementById('DetailsView2_ABNVali');
            //ValidatorEnable(myVal, true);
            //var myVal = document.getElementById('DetailsView2_ANNUAL_CONSUMPTIONVali');
            //ValidatorEnable(myVal, true);


            $('#DetailsView2_TRADING_NAME').show();

            if ($('#DetailsView2_SelCALL_TYPE').val() == 'D2D') {
                //$('#DetailsView2_BILLNAME1').hide();
                //$('#DetailsView2_BILLNAME2').hide();
                $('#DetailsView2_ACCOUNT_ID').hide();
                $('#DetailsView2_SelPAYMENT_OPTION').hide();

            }
            if ($('#DetailsView2_SelCALL_TYPE').val() != 'D2D') {
                //$('#DetailsView2_BILLNAME1').show();
                //$('#DetailsView2_BILLNAME2').show();
                $('#DetailsView2_ACCOUNT_ID').show();
                $('#DetailsView2_SelPAYMENT_OPTION').show();
            }
            ///var DetailsView2_EMAILVali = document.getElementById('DetailsView2_EMAILVali');
            ///ValidatorEnable(DetailsView2_EMAILVali, true);
            $('#DetailsView2_SelCUST2').hide();
            ///var DetailsView2_CURRENT_ELECTRICITY_RETAILERVali = document.getElementById('DetailsView2_CURRENT_ELECTRICITY_RETAILERVali');
            ///ValidatorEnable(DetailsView2_CURRENT_ELECTRICITY_RETAILERVali, true);


        }

    });



    function SelCUST2Changed() {
        if ($('#DetailsView2_SelCUST2').val() == 'YES') {
            $('#DetailsView2_SelTITLE_CUST_2').show();
            $('#DetailsView2_FIRST_NAME_CUST_2').show();
            $('#DetailsView2_LAST_NAME_CUST_2').show();
            $('#DetailsView2_DOB_CUST_2').show();
            $('#DetailsView2_DRIVERS_LICENCE_CUST_2').show();
            $('#DetailsView2_HPHONE_CUST_2').show();
            $('#DetailsView2_BPHONE_CUST_2').show();
            $('#DetailsView2_MOBILE_CUST_2').show();
            $('#DetailsView2_EMAIL_CUST_2').show();
            $('#DetailsView2_SelRELATIONSHIP_CODE').show();

        }
        else {
            $('#DetailsView2_SelTITLE_CUST_2').hide();
            $('#DetailsView2_FIRST_NAME_CUST_2').hide();
            $('#DetailsView2_LAST_NAME_CUST_2').hide();
            $('#DetailsView2_DOB_CUST_2').hide();
            $('#DetailsView2_DRIVERS_LICENCE_CUST_2').hide();
            $('#DetailsView2_HPHONE_CUST_2').hide();
            $('#DetailsView2_BPHONE_CUST_2').hide();
            $('#DetailsView2_MOBILE_CUST_2').hide();
            $('#DetailsView2_EMAIL_CUST_2').hide();
            $('#DetailsView2_SelRELATIONSHIP_CODE').hide();
        }
    }


    function SelCUSTOMER_TYPEChanged() {
        if ($('#DetailsView2_SelCUSTOMER_TYPE').val() == 'RESD') {

            $('#DetailsView2_BILLNAME1').hide();
            $('#DetailsView2_BILLNAME2').hide();



            if ($('#DetailsView2_SelCALL_TYPE').val() == 'D2D') {
                $('#DetailsView2_SelCUST2').show();
                $('#DetailsView2_ACCOUNT_ID').hide();
                $('#DetailsView2_SelPAYMENT_OPTION').hide();
            }
            if ($('#DetailsView2_SelCALL_TYPE').val() != 'D2D') {
                $('#DetailsView2_SelCUST2').hide();
                $('#DetailsView2_ACCOUNT_ID').show();
                $('#DetailsView2_SelPAYMENT_OPTION').show();
            }

            $('#DetailsView2_SelSOHO').show();

            $('#DetailsView2_TRADING_NAME').hide();

            if ($('#DetailsView2_ANNUAL_CONSUMPTION').val() == '') {
                document.getElementById('DetailsView2_ANNUAL_CONSUMPTION').value = "2";
            }

            if ($('#DetailsView2_SelSOHO').val() == 'Not SOHO') {
                $('#DetailsView2_lblCUSTOMER_TYPE').hide();

                $('#DetailsView2_COMPANY_NAME').hide();
                $('#DetailsView2_COMPANY_POSITION').hide();
                $('#DetailsView2_ABN').hide();
                //$('#DetailsView2_ANNUAL_CONSUMPTION').hide();
                ///var myVal = document.getElementById('DetailsView2_COMPANY_NAMEVali');
                ///ValidatorEnable(myVal, false);
                ///var myVal = document.getElementById('DetailsView2_COMPANY_POSITIONVali');
                ///ValidatorEnable(myVal, false);
                ///var myVal = document.getElementById('DetailsView2_ABNVali');
                ///ValidatorEnable(myVal, false);
                //var myVal = document.getElementById('DetailsView2_ANNUAL_CONSUMPTIONVali');
                //ValidatorEnable(myVal, false);
            }
            if ($('#DetailsView2_SelSOHO').val() != 'Not SOHO') {
                $('#DetailsView2_lblCUSTOMER_TYPE').show();

                $('#DetailsView2_COMPANY_NAME').show();
                $('#DetailsView2_COMPANY_POSITION').show();
                $('#DetailsView2_ABN').show();
                //$('#DetailsView2_ANNUAL_CONSUMPTION').show();
                ///var myVal = document.getElementById('DetailsView2_COMPANY_NAMEVali');
                ///ValidatorEnable(myVal, true);
                ///var myVal = document.getElementById('DetailsView2_COMPANY_POSITIONVali');
                ///ValidatorEnable(myVal, true);
                ///var myVal = document.getElementById('DetailsView2_ABNVali');
                ///ValidatorEnable(myVal, true);
                //var myVal = document.getElementById('DetailsView2_ANNUAL_CONSUMPTIONVali');
                //ValidatorEnable(myVal, true);
            }



            ///var myVal = document.getElementById('DetailsView2_EMAILVali');
            ///ValidatorEnable(myVal, false);

            if ($('#DetailsView2_SelCALL_TYPE').val() == 'D2D') {
                $('#DetailsView2_SelCUST2').show();
                $('#DetailsView2_ACCOUNT_ID').hide();
                $('#DetailsView2_SelPAYMENT_OPTION').hide();
            }
            if ($('#DetailsView2_SelCALL_TYPE').val() != 'D2D') {
                $('#DetailsView2_SelCUST2').hide();
                $('#DetailsView2_ACCOUNT_ID').show();
                $('#DetailsView2_SelPAYMENT_OPTION').show();
            }
            ///var myVal = document.getElementById('DetailsView2_CURRENT_ELECTRICITY_RETAILERVali');
            ///ValidatorEnable(myVal, false);
        }

        if ($('#DetailsView2_SelCUSTOMER_TYPE').val() == 'SME') {

            $('#DetailsView2_BILLNAME1').show();
            $('#DetailsView2_BILLNAME2').show();
            $('#DetailsView2_lblCUSTOMER_TYPE').show();

            $('#DetailsView2_SelSOHO').hide();
            $('#DetailsView2_COMPANY_NAME').show();
            $('#DetailsView2_COMPANY_POSITION').show();
            $('#DetailsView2_ABN').show();

            if ($('#DetailsView2_ANNUAL_CONSUMPTION').val() == '') {
                document.getElementById('DetailsView2_ANNUAL_CONSUMPTION').value = "1";
            }


            //$('#DetailsView2_ANNUAL_CONSUMPTION').show();
            ///var myVal = document.getElementById('DetailsView2_COMPANY_NAMEVali');
            ///ValidatorEnable(myVal, true);
            ///var myVal = document.getElementById('DetailsView2_COMPANY_POSITIONVali');
            ///ValidatorEnable(myVal, true);
            ///var myVal = document.getElementById('DetailsView2_ABNVali');
            ///ValidatorEnable(myVal, true);
            //var myVal = document.getElementById('DetailsView2_ANNUAL_CONSUMPTIONVali');
            //ValidatorEnable(myVal, true);

            $('#DetailsView2_TRADING_NAME').show();

            if ($('#DetailsView2_SelCALL_TYPE').val() == 'D2D') {
                //$('#DetailsView2_BILLNAME1').hide();
                //$('#DetailsView2_BILLNAME2').hide();
                $('#DetailsView2_ACCOUNT_ID').hide();
                $('#DetailsView2_SelPAYMENT_OPTION').hide();
            }

            if ($('#DetailsView2_SelCALL_TYPE').val() != 'D2D') {
                //$('#DetailsView2_BILLNAME1').show();
                //$('#DetailsView2_BILLNAME2').show();
                $('#DetailsView2_ACCOUNT_ID').show();
                $('#DetailsView2_SelPAYMENT_OPTION').show();
            }

            ///var myVal = document.getElementById('DetailsView2_EMAILVali');
            ///ValidatorEnable(myVal, true);
            $('#DetailsView2_SelCUST2').hide();
            ///var myVal = document.getElementById('DetailsView2_CURRENT_ELECTRICITY_RETAILERVali');
            ///ValidatorEnable(myVal, true);
        }
    }


    function SelPAYMENT_OPTIONChanged() {
        if ($('#DetailsView2_SelPAYMENT_OPTION').val() == 'RPO') {
            $('#DetailsView2_RPO_FIRST_PAYMENT_DATE').show();
            $('#DetailsView2_RPO_ELEC_MONTH').show();
            $('#DetailsView2_RPO_ELEC_FORTN').show();
            $('#DetailsView2_RPO_GAS_MONTH').show();
            $('#DetailsView2_RPO_GAS_FORTN').show();
            $('#DetailsView2_RPO_COMB_MONTH').show();
            $('#DetailsView2_RPO_COMB_FORTN').show();
            $('#DetailsView2_RPO_FREQ_SELECTION').show();
        }
        else {
            $('#DetailsView2_RPO_FIRST_PAYMENT_DATE').hide();
            $('#DetailsView2_RPO_ELEC_MONTH').hide();
            $('#DetailsView2_RPO_ELEC_FORTN').hide();
            $('#DetailsView2_RPO_GAS_MONTH').hide();
            $('#DetailsView2_RPO_GAS_FORTN').hide();
            $('#DetailsView2_RPO_COMB_MONTH').hide();
            $('#DetailsView2_RPO_COMB_FORTN').hide();
            $('#DetailsView2_RPO_FREQ_SELECTION').hide();

        }

    }

    function FuelTypeChanged() {


        if ($('#DetailsView2_SelFuelType').val() == 'GAS_ONLY') {
            $("#DetailsView2_NETWORK_AREA").val('GAS NETORK AREA');
        }
        if ($('#DetailsView2_SelFuelType').val() == 'ELEC_ONLY') {
            $("#DetailsView2_NETWORK_AREA").val('ELECTRICITY NETORK AREA');
        }
        if ($('#DetailsView2_SelFuelType').val() == 'DUAL_FUEL') {
            $("#DetailsView2_NETWORK_AREA").val('ELECTRICITY NETORK AREA');
        }
    }

    function ABNChanged() {

        var checkStr = $('#DetailsView2_ABN').val();

        //var abn_fmt_str = (fmt_str) ? ‘\nThe ABN is a unique 11 digit number formed from a 9 digit unique identifier and two prefix check digits.\nThe Australian Business Register structure an ABN as XX XXX XXX XXX to assist readability.’ : ”;
        if (checkStr.length != 11 && checkStr.length != 14) {
            alert("ABN Must be 11 or 14 digits long");
        }
        else {
            var ch1 = parseInt(checkStr.charAt(0));
            var ch2 = parseInt(checkStr.charAt(1));
            var ch3 = parseInt(checkStr.charAt(2));
            var ch4 = parseInt(checkStr.charAt(3));
            var ch5 = parseInt(checkStr.charAt(4));
            var ch6 = parseInt(checkStr.charAt(5));
            var ch7 = parseInt(checkStr.charAt(6));
            var ch8 = parseInt(checkStr.charAt(7));
            var ch9 = parseInt(checkStr.charAt(8));
            var ch10 = parseInt(checkStr.charAt(9));
            var ch11 = parseInt(checkStr.charAt(10));

            var sum = 10 * (ch1 - 1) + ch2 + 3 * ch3 + 5 * ch4 + 7 * ch5 + 9 * ch6 + 11 * ch7 + 13 * ch8 + 15 * ch9 + 17 * ch10 + 19 * ch11;

            var chk = sum % 89;

            if (chk != 0) {
                alert("ABN is NOT valid!");
                $('#DetailsView2_ABN').focus();
            }

        }

    }



    function NMIChanged() {
        var checkStr = $('#DetailsView2_NMI').val();
        if (checkStr.length != 11) {
            alert("NMI Must be 11 digits long");
        }
        else {
            var hash1 = { 0: "12", 1: "13", 2: "5", 3: "6", 4: "7", 5: "8", 6: "9", 7: "10", 8: "11", 9: "12" };
            var hash2 = { 0: "15", 1: "17", 2: "1", 3: "3", 4: "5", 5: "7", 6: "9", 7: "2", 8: "4", 9: "6" };

            var ch1 = parseInt(hash1[checkStr.charAt(0)]);
            var ch2 = parseInt(hash2[checkStr.charAt(1)]);
            var ch3 = parseInt(hash1[checkStr.charAt(2)]);
            var ch4 = parseInt(hash2[checkStr.charAt(3)]);
            var ch5 = parseInt(hash1[checkStr.charAt(4)]);
            var ch6 = parseInt(hash2[checkStr.charAt(5)]);
            var ch7 = parseInt(hash1[checkStr.charAt(6)]);
            var ch8 = parseInt(hash2[checkStr.charAt(7)]);
            var ch9 = parseInt(hash1[checkStr.charAt(8)]);
            var ch10 = parseInt(hash2[checkStr.charAt(9)]);
            var ch11 = parseInt(checkStr.charAt(10));

            var sum = ch1 + ch2 + ch3 + ch4 + ch5 + ch6 + ch7 + ch8 + ch9 + ch10;
            var chk = sum % 10 + ch11;

            if (chk != 10) {
                alert("NMI is NOT valid!" + chk);
                $('#DetailsView2_NMI').focus();
            }
        }
    }


    function DPIChanged() {
        var checkStr = $('#DetailsView2_DPI').val();
        if (checkStr.length != 11) {
            alert("DPI Must be 11 digits long");
        }
        else {
            var hash1 = { 0: "12", 1: "13", 2: "5", 3: "6", 4: "7", 5: "8", 6: "9", 7: "10", 8: "11", 9: "12" };
            var hash2 = { 0: "15", 1: "17", 2: "1", 3: "3", 4: "5", 5: "7", 6: "9", 7: "2", 8: "4", 9: "6" };

            var ch1 = parseInt(hash1[checkStr.charAt(0)]);
            var ch2 = parseInt(hash2[checkStr.charAt(1)]);
            var ch3 = parseInt(hash1[checkStr.charAt(2)]);
            var ch4 = parseInt(hash2[checkStr.charAt(3)]);
            var ch5 = parseInt(hash1[checkStr.charAt(4)]);
            var ch6 = parseInt(hash2[checkStr.charAt(5)]);
            var ch7 = parseInt(hash1[checkStr.charAt(6)]);
            var ch8 = parseInt(hash2[checkStr.charAt(7)]);
            var ch9 = parseInt(hash1[checkStr.charAt(8)]);
            var ch10 = parseInt(hash2[checkStr.charAt(9)]);
            var ch11 = parseInt(checkStr.charAt(10));

            var sum = ch1 + ch2 + ch3 + ch4 + ch5 + ch6 + ch7 + ch8 + ch9 + ch10;
            var chk = sum % 10 + ch11;

            if (chk != 10) {
                alert("DPI is NOT valid!" + chk);
                $('#DetailsView2_DPI').focus();
            }
        }
    }